// webpack.prod.js
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); // 引入CleanWebpackPlugin插件
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')

module.exports = merge(common, {
  entry: {
    main: './src/main.js'
  },
  output: {
    filename: '[name]-[contenthash:8].bundle.js',
    path: path.join(__dirname, '/dist')
  },
  devtool: 'none',
  optimization: {
    usedExports: true,
    minimize: true,
    concatenateModules: true
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader'
        ]
      },
      {
        test: /\.less$/,
        use: [
          MiniCssExtractPlugin.loader,
          'css-loader',
          'less-loader'
        ]
      }
    ]
  },
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        { from: 'public/favicon.ico' }
      ],
    }),
    new MiniCssExtractPlugin({
      filename: '[name]-[contenthash:8].css',
    })
  ]
})